<!--
 * @Description: 墙布生产任务单
 *
 * @Author: guichengcai<guichengcai>
 * @Date: 2023-07-03 17:11:54
 * @FilePath: /yuxiuproweb/src/views/reportforms/sale/index.vue
-->
<template>
  <div class="app-container">
    <el-form
      :model="queryParams"
      ref="queryForm"
      size="small"
      :inline="true"
      v-show="showSearch"
      label-width="68px"
    >
      <el-form-item label="订单编号" prop="orderId">
        <el-input
          v-model="queryParams.orderId"
          placeholder="请输入订单编号"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="客户名称" prop="clientId">
        <el-select
          v-model="queryParams.clientId"
          clearable
          filterable
          placeholder="请选择客户"
          remote
          reserve-keyword
          :remote-method="getListClient"
          @keyup.enter.native="handleQuery"
        >
          <el-option
            v-for="item in clientList"
            :key="item.clientId"
            :label="item.clientName"
            :value="item.clientId"
          >
          </el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="省份" prop="province">
        <el-input
          v-model="queryParams.province"
          placeholder="请输入省份"
          clearable
          @keyup.enter.native="handleQuery"
        />
      </el-form-item>
      <el-form-item label="单据类型" prop="orderType">
        <el-select
          v-model="queryParams.orderType"
          placeholder="请选择单据类型"
          style="width: 100%"
          @change="handleQuery"
          clearable
        >
          <el-option
            v-for="dict in dict.type.qb_order_state"
            :key="dict.value"
            :label="dict.label"
            :value="dict.value"
          />
        </el-select>
      </el-form-item>
      <el-form-item label="下单日期" prop="createDateObj">
        <el-date-picker
          align="center"
          style="width: 240px"
          v-model="createDateObj"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
          :default-time="['00:00:00', '23:59:59']"
          format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="提交日期" prop="subTimeObj">
        <el-date-picker
          align="center"
          style="width: 240px"
          v-model="subTimeObj"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
          :default-time="['00:00:00', '23:59:59']"
          format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="初审日期" prop="approvedTimeObj">
        <el-date-picker
          align="center"
          style="width: 240px"
          v-model="approvedTimeObj"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
          :default-time="['00:00:00', '23:59:59']"
          format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="审核日期" prop="financialApprovedTimeObj">
        <el-date-picker
          align="center"
          style="width: 240px"
          v-model="financialApprovedTimeObj"
          type="daterange"
          range-separator="至"
          start-placeholder="开始日期"
          end-placeholder="结束日期"
          value-format="yyyy-MM-dd HH:mm:ss"
          :default-time="['00:00:00', '23:59:59']"
          format="yyyy-MM-dd"
        >
        </el-date-picker>
      </el-form-item>
      <el-form-item label="状态" prop="state">
        <el-select
          style="width: 100%"
          v-model="queryParams.state"
          filterable
          clearable
          placeholder="请选择状态"
          @change="handleQuery"
        >
          <el-option label="新建" :value="1"></el-option>
          <el-option label="提交" :value="2"></el-option>
          <el-option label="初审" :value="3"></el-option>
          <el-option label="审核" :value="4"></el-option>
          <el-option label="生产中" :value="5"></el-option>
          <el-option label="生产完成" :value="6"></el-option>
          <el-option label="已发货" :value="7"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item>
        <el-button
          type="primary"
          icon="el-icon-search"
          size="mini"
          @click="handleQuery"
          >搜索</el-button
        >
        <el-button icon="el-icon-refresh" size="mini" @click="resetQuery"
          >重置</el-button
        >
        <el-button-group style="margin-left: 10px">
          <el-button
            :type="!queryParams.accurate ? 'primary' : 'default'"
            @click="queryParams.accurate = false"
            size="mini"
            >模糊</el-button
          >
          <el-button
            :type="queryParams.accurate ? 'primary' : 'default'"
            @click="queryParams.accurate = true"
            size="mini"
            >精确</el-button
          >
        </el-button-group>
      </el-form-item>
    </el-form>

    <el-row :gutter="10" class="mb8">
      <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleAdd"
          v-hasPermi="['qb:order:add']"
          >新增</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-download"
          size="mini"
          @click="handleExport"
          v-hasPermi="['pro:record:export']"
          >导出</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-s-check"
          size="mini"
          @click="handleCheck"
          v-hasRole="['money']"
          >初审审核</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="success"
          plain
          icon="el-icon-s-check"
          size="mini"
          @click="handleCheck"
          v-hasRole="['money']"
          >审单审核</el-button
        >
      </el-col>
      <!-- <el-col :span="1.5">
        <el-button
          type="primary"
          plain
          icon="el-icon-plus"
          size="mini"
          @click="handleSchedule"
          v-hasRole="['shengchang']"
          >去排单</el-button
        >
      </el-col> -->
      <el-col :span="1.5">
        <el-button
          type="danger"
          plain
          icon="el-icon-close"
          size="mini"
          v-hasRole="['manager']"
          @click="handleClose"
          >关闭订单</el-button
        >
      </el-col>
      <el-col :span="1.5">
        <el-button
          type="warning"
          plain
          icon="el-icon-check"
          size="mini"
          v-hasRole="['manager']"
          @click="handleNoClose"
          >取消关闭</el-button
        >
      </el-col>
      <right-toolbar
        :showSearch.sync="showSearch"
        @queryTable="getList"
      ></right-toolbar>
    </el-row>

    <el-table
      ref="tableList"
      v-loading="loading"
      :data="recordList"
      @selection-change="handleSelectionChange"
      :max-height="maxHeight"
      show-summary
      :summary-method="getSummaries"
      :row-style="{ height: '20px' }"
      :cell-style="{ padding: '8px 0' }"
      border
      size="mini"
    >
      <el-table-column type="selection" width="55" align="center" fixed />
      <template v-for="(i, index) in tableForm.item">
        <el-table-column
          :key="index"
          :prop="i.itemcode"
          :columnKey="i.itemcode"
          :label="i.itemname"
          :align="i.aligntype ? i.aligntype : 'center'"
          :min-width="i.minwidth"
          :width="!!i.width ? i.width : ''"
          :show-overflow-tooltip="i.overflow ? true : false"
          :sortable="i.sortable ? true : false"
          :fixed="i.fixed"
          v-if="i.displaymark ? true : false"
        >
          <template slot-scope="scope">
            <div v-if="i.itemcode == 'state'">
              <span v-if="scope.row.isDelete == 1">已关闭</span>
              <div v-else>
                <span v-if="scope.row[i.itemcode] == 1">新建</span>
                <span v-else-if="scope.row[i.itemcode] == 2">提交</span>
                <span v-else-if="scope.row[i.itemcode] == 3">初审</span>
                <span v-else-if="scope.row[i.itemcode] == 4">审核</span>
                <span v-else-if="scope.row[i.itemcode] == 5">生产中</span>
                <span v-else-if="scope.row[i.itemcode] == 6">生产完成</span>
                <span v-else-if="scope.row[i.itemcode] == 7">已发货</span>
                <span v-else style="color: red">异常</span>
              </div>
            </div>
            <div v-else-if="i.itemcode == 'isUsingRebate'">
              <span v-if="scope.row[i.itemcode] == 0">否</span>
              <span v-else>是</span>
            </div>
            <div v-else-if="i.itemcode == 'orderType'">
              <span>{{
                dict.label.qb_order_state[scope.row[i.itemcode]]
              }}</span>
            </div>
            <span v-else>{{ scope.row[i.itemcode] }}</span>
          </template>
        </el-table-column>
      </template>

      <el-table-column
        label="操作"
        align="center"
        class-name="small-padding fixed-width"
        width="120"
        fixed="right"
      >
        <template slot-scope="scope">
          <!-- :disabled="scope.row.state === '4'" -->
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleUpdate(scope.row)"
            >修改</el-button
          >
          <el-button
            size="mini"
            type="text"
            icon="el-icon-edit"
            @click="handleReturn(scope.row)"
            >返单</el-button
          >
        </template>
      </el-table-column>
    </el-table>

    <pagination
      v-show="total > 0"
      :total="total"
      :page.sync="queryParams.pageNum"
      :limit.sync="queryParams.pageSize"
      @pagination="getList"
    />
    <!-- 添加或修改订单对话框 -->
    <el-dialog
      :close-on-click-modal="false"
      :title="title"
      :visible.sync="open"
      width="98vw"
      :top="'2vh !important'"
      append-to-body
      :fullscreen="true"
    >
      <formEdit
        ref="formEdit"
        :brandList="brandList"
        @handleUpdate="handleUpdate"
      ></formEdit>
      <div slot="footer" class="dialog-footer">
        <div v-if="form.isDelete != 1" style="margin-right: 10px">
          <el-button
            type="success"
            @click="submitState1('保存')"
            v-if="[1, 2, 3, 4].includes(form.state)"
            >保 存</el-button
          >
          <el-button
            type="primary"
            @click="submitState2"
            v-if="form.orderId && form.state == 1"
            >提 交</el-button
          >
          <el-button
            type="primary"
            @click="submitChange"
            v-if="form.orderId && form.state == 2"
            v-hasRole="['money']"
            >变更</el-button
          >
          <el-button
            type="primary"
            @click="submitState3"
            v-if="form.orderId && form.state == 2"
            v-hasRole="['money']"
            >初审</el-button
          >
          <el-button
            type="primary"
            @click="submitState4"
            v-if="form.orderId && form.state == 3"
            v-hasRole="['money']"
            >审核</el-button
          >
          <el-button
            type="warning"
            @click="submitState2To1"
            v-if="form.orderId && form.state == 2"
            v-hasRole="['money']"
            >回 退</el-button
          >
          <el-button
            type="warning"
            @click="submitState4To2"
            v-if="form.orderId && [3, 4].includes(form.state)"
            v-hasRole="['money']"
            >弃 审</el-button
          >
        </div>

        <el-button @click="cancel">取 消</el-button>
      </div>
    </el-dialog>
    <el-dialog
      :close-on-click-modal="false"
      :title="'订单返单'"
      :visible.sync="returnOrderOpen"
      width="100vw"
      :top="'0vh !important'"
      append-to-body
      :fullscreen="true"
    >
      <returnOrder ref="returnOrder"></returnOrder>
    </el-dialog>
  </div>
</template>

<script>
import {
  allList,
  addOrder,
  updateOrder,
  auditOrder,
  closeOrder,
  nocloseOrder,
  getOrder,
  giveUpOrder,
  changeOrder,
} from "@/api/qb";
import commonMix from "@/utils/mixins/common";
import { listBrand } from "@/api/money/brand";
import { listClient, getClient } from "@/api/mes/md/client";
import formEdit from "./components/formEdit.vue";
import returnOrder from "./components/returnOrder.vue";
import { tableList } from "./components/tablecolums.js";
export default {
  mixins: [commonMix],
  name: "Record",
  components: { formEdit, returnOrder },
  dicts: ["qb_order_state"],
  data() {
    return {
      // 遮罩层
      loading: true,
      // 选中数组
      ids: [],
      // 非单个禁用
      single: true,
      // 非多个禁用
      multiple: true,
      // 显示搜索条件
      showSearch: true,
      // 总条数
      total: 0,
      // 交易记录表格数据
      recordList: [],
      // 弹出层标题
      title: "",
      // 是否显示弹出层
      open: false,
      returnOrderOpen: false,
      clientList: [], //客户
      // 查询参数
      queryParams: {
        pageNum: 1,
        pageSize: 100,
        orderId: null,
        clientId: null,
        clientName: null,
        province: null,
        brandId: null,
        state: null,
        orderType: null,
        accurate: false,
      },
      createDateObj: null,
      subTimeObj: null,
      approvedTimeObj: null,
      financialApprovedTimeObj: null,
      brandList: [],
      // 表单参数
      form: {
        isDelete: 0,
        state: 1,
      },
      // 表单校验
      rules: {},
      tableForm: tableList,
      selRows: [],
    };
  },
  created() {
    this.getList();
    this.getListClient(); //客户
    // this.getBrandList(); //品牌 已废弃
  },
  methods: {
    /** 保存按钮 */
    async submitState1(mes) {
      await this.$refs.formEdit.$refs["form"].validate();

      if (this.$refs.formEdit.form.orderId != null) {
        // 判断 状态新建直接修改，生产中，变更单,判断是否有修改
        let isEqual = false;
        this.$refs.formEdit.lst.forEach((obj1, index) => {
          const obj2 = this.$refs.formEdit.copyList[index];
          if (
            obj1.length != obj2.length ||
            obj1.name != obj2.name ||
            obj1.height != obj2.height ||
            obj1.technology != obj2.technology
          ) {
            isEqual = true;
            // this.$refs.formEdit.lst[index].variationStatus = "已变更";
          }
        });
        if (this.$refs.formEdit.form.state != 1 && isEqual) {
          this.$message.error("当前状态下，不可修改商品信息！！");
          return;
        }
        this.updateOrder(mes);
      } else {
        // 修改和新的参数结构不一致
        for (var i = 0; i < this.$refs.formEdit.lst.length; i++) {
          this.$delete(this.$refs.formEdit.lst[i], "isEdit");
          this.$delete(this.$refs.formEdit.lst[i], "rownum");
        }
        const query = {
          appOrder: {
            ...this.$refs.formEdit.form,
          },
          productList: this.$refs.formEdit.lst,
        };
        addOrder(query).then(({ data }) => {
          this.$modal.msgSuccess("新增成功");
          this.open = false;
          this.getList();
          // this.goPages(data);
        });
      }
    },
    /* 提交按钮 1->2*/
    async submitState2() {
      if (this.$refs.formEdit.form.state == 1) {
        this.$refs.formEdit.form.state = 2;
        this.submitState1("提交");
        // this.updateOrder("提交");
      } else {
        this.$message.error("当前状态不可提交！！");
      }
    },
    // 初审-如果金额正确 2->3
    submitState3() {
      auditOrder({ orderId: this.form.orderId }).then((res) => {
        // console.log(res) 没有数据返回
        this.$modal.msgSuccess("初审成功");
        this.open = false;
        this.getList();
      });
    },
    //审核-如果已扣款 3->4
    submitState4() {
      auditOrder({ orderId: this.form.orderId }).then((res) => {
        // console.log(res) 没有数据返回
        this.$modal.msgSuccess("审核成功");
        this.open = false;
        this.getList();
      });
    },
    // 回退
    submitState2To1() {
      if (this.$refs.formEdit.form.state == 2) {
        this.$refs.formEdit.form.state = 1;
        // this.updateOrder("回退");
        const query = {
          ...this.$refs.formEdit.form,
          productList: this.$refs.formEdit.copyList, //防止回退时修改数据
        };
        updateOrder(query).then(({ data }) => {
          this.$modal.msgSuccess("回退成功");
          this.open = false;
          this.getList();
        });
      } else {
        this.$message.error("当前状态不可回退！！");
      }
    },
    // 弃审 将状态改为2提交，金额回退账户
    submitState4To2() {
      //初审、审核、生产中
      if ([3, 4, 5].includes(this.$refs.formEdit.form.state)) {
        giveUpOrder(this.$refs.formEdit.form).then((res) => {
          // this.$emit()
          this.$message.success("弃审成功");
          this.getList();
          this.open = false;
          this.$refs.formEdit.form.state = 2;
          this.handleUpdate(this.$refs.formEdit.form);
        });
      } else {
        this.$message.error("当前状态不可弃审！！");
      }
    },
    // 变更
    submitChange() {
      if ([2].includes(this.$refs.formEdit.form.state)) {
        // 判断 状态新建直接修改，生产中，变更单,判断是否有修改
        let isEqual = false;
        this.$refs.formEdit.lst.forEach((obj1, index) => {
          const obj2 = this.$refs.formEdit.copyList[index];
          if (
            obj1.length != obj2.length ||
            obj1.name != obj2.name ||
            obj1.height != obj2.height ||
            obj1.technology != obj2.technology
          ) {
            isEqual = true;
            this.$refs.formEdit.lst[index].variationStatus = "已变更";
          }
        });
        // return;
        if (isEqual) {
          this.$confirm("是否确认变更?", "提示", {
            confirmButtonText: "确定",
            cancelButtonText: "取消",
            type: "warning",
          })
            .then(() => {
              for (var i = 0; i < this.$refs.formEdit.lst.length; i++) {
                this.$delete(this.$refs.formEdit.lst[i], "isEdit");
                this.$delete(this.$refs.formEdit.lst[i], "rownum");
              }
              const query = {
                ...this.$refs.formEdit.form,
                productList: this.$refs.formEdit.lst,
              };
              changeOrder(query).then((res) => {
                this.$modal.msgSuccess("变更成功");
                this.getList();
                this.open = false;
                this.handleUpdate(this.$refs.formEdit.form);
              });
            })
            .catch(() => {});
        } else {
          this.$message.error("商品没有修改，无需变更");
        }
      } else {
        this.$message.error("当前状态不可变更！！");
      }
    },
    // 保存
    updateOrder(mes) {
      // 修改和新的参数结构不一致
      for (var i = 0; i < this.$refs.formEdit.lst.length; i++) {
        this.$delete(this.$refs.formEdit.lst[i], "isEdit");
        this.$delete(this.$refs.formEdit.lst[i], "rownum");
      }
      const query = {
        ...this.$refs.formEdit.form,
        productList: this.$refs.formEdit.lst,
      };
      updateOrder(query).then(({ data }) => {
        this.$modal.msgSuccess(mes + "成功");
        this.open = false;
        this.getList();
      });
    },
    getListClient(clientName = "") {
      listClient({
        pageNum: 1,
        pageSize: 100,
        enableFlag: "Y",
        clientName,
        // id: "1107",
      }).then(({ rows }) => {
        this.clientList = rows;
      });
    },

    /** 新增按钮操作 */
    handleAdd() {
      this.form = {
        isDelete: 0,
        state: 1,
      };
      this.open = true;
      this.title = "新增订单";
      this.$nextTick(() => {
        this.$refs.formEdit.deliveryMethod = "";
        this.$refs.formEdit.deliveryMethodId = "";
        this.$refs.formEdit.lst = [];
        this.$refs.formEdit.clientRow = {};
        this.reset();
      });
    },
    /** 客服核对or财务核对*/
    handleCheck() {
      if (this.ids.length != 1) {
        this.$message.error("一次只能选择一个订单核对");
        return;
      }
      // 后台处理会修改单据状态,客服核对为2审核,财务核对为3已扣款
      // 状态1新建2审核3已扣款4生产中5生产完成6已发货
      // bug 后台根据登录者身份来判定是否有权限审核,但没有做判断else的返回结果,目前可以一直审核到状态6已发货
      auditOrder({ orderId: this.ids[0] }).then((res) => {
        // console.log(res) 没有数据返回
        this.$modal.msgSuccess("核对成功");
        this.getList();
      });
    },
    // 去排单
    handleSchedule() {
      if (this.ids.length != 1) {
        this.$message.error("一次只能选择一个订单排单");
        return;
      }
      auditOrder({ orderId: this.ids[0] }).then((res) => {
        // console.log(res) 没有数据返回
        this.$modal.msgSuccess("排单成功");
        this.getList();
      });
    },
    // 关闭订单
    handleClose() {
      if (this.ids.length == 0) {
        this.$message.error("请选择要关闭的订单");
        return;
      }
      closeOrder(this.ids).then((res) => {
        // console.log(res) //没有数据返回
        if (res.code == 200) {
          this.$modal.msgSuccess(res.msg || "订单关闭成功");
          this.getList();
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    handleNoClose() {
      if (this.ids.length == 0) {
        this.$message.error("请选择要取消关闭的订单");
        return;
      }

      nocloseOrder(this.ids).then((res) => {
        if (res.code == 200) {
          this.$modal.msgSuccess(res.msg || "操作成功");
          this.getList();
        } else {
          this.$message.error(res.msg);
        }
      });
    },
    // 获取数据
    async getOrderData(orderId) {
      const { data } = await getOrder(orderId);
      return data;
    },
    /** 修改按钮操作 */
    async handleUpdate(row) {
      this.form = row;
      const orderId = row.orderId || this.ids;
      const data = await this.getOrderData(orderId);
      // console.log("data", data);
      this.open = true;
      var stateVal = {
        1: "新建",
        2: "提交",
        3: "初审",
        4: "审核",
        5: "生产中",
        6: "生产完成",
        7: "发货",
        8: "关闭",
      };
      this.title =
        "订单明细（" +
        stateVal[row.isDelete == 1 ? 8 : row.state] +
        "）" +
        row.orderId;
      this.$nextTick(() => {
        this.reset();
        this.$refs.formEdit.form = { ...data };
        this.$refs.formEdit.form.clientName = row.clientName;
        this.$refs.formEdit.lst = data.productList;
        this.$refs.formEdit.deliveryMethod = "";
        this.$refs.formEdit.deliveryMethodId = "";

        this.$refs.formEdit.initClient(data.clientId); //初始化客户信息 账户金额
        for (var i = 0; i < this.$refs.formEdit.lst.length; i++) {
          var item = this.$refs.formEdit.lst[i];
          this.$set(item, "isEdit", false);
        }
        this.$refs.formEdit.copyList = JSON.parse(
          JSON.stringify(data.productList)
        );
        // this.$refs.formEdit.getClientList(row.clientId);
        this.$refs.formEdit.listCompany();
        this.$refs.formEdit.zeroCutFeeInputShow = false;
        this.$refs.formEdit.logisticsFeeInputShow = false;
        this.$refs.formEdit.packingFeeInputShow = false;
      });
    },
    /** 查询交易记录列表 */
    getList() {
      this.loading = true;
      const params = {
        ...this.queryParams,
        createDateStart: this.createDateObj?.[0] || null,
        createDateEnd: this.createDateObj?.[1] || null,
        subTimeStart: this.subTimeObj?.[0] || null,
        subTimeEnd: this.subTimeObj?.[1] || null,
        approvedTimeStart: this.approvedTimeObj?.[0] || null,
        approvedTimeEnd: this.approvedTimeObj?.[1] || null,
        financialApprovedTimeStart: this.financialApprovedTimeObj?.[0] || null,
        financialApprovedTimeEnd: this.financialApprovedTimeObj?.[1] || null,
      };
      allList(params).then((response) => {
        this.recordList = response.rows;
        this.total = response.total;
        this.loading = false;
      });
    },
    // 取消按钮
    cancel() {
      this.open = false;
      this.reset();
    },
    // 表单重置
    reset() {
      this.$refs.formEdit.form = {
        isUrgent: 0, //加急
        isUsingRebate: 0,
        productList: [],

        state: 1, // 1新建
        consignee: "",
        notes: "",
        deliveryAddress: "",
        deliveryAddressId: "",
        deliveryMethod: "",
        telnum: "",
        brandId: null,
        brandName: "",
        region: [],
        province: "", // 省份名称
        city: "", // 城市名称
        district: "", // 区名称
        orderType: "SA",
        packingFee: 0,
        logisticsFee: 0,
        zeroCutFee: 0,
        totalPrice: 0,
        postageModeOfPayment: null,
        clientId: null,
      };
      this.$refs.formEdit.lst = [];
      this.resetForm("form");
    },
    /** 搜索按钮操作 */
    handleQuery() {
      this.queryParams.pageNum = 1;
      this.getList();
    },
    /** 重置按钮操作 */
    resetQuery() {
      this.resetForm("queryForm");
      this.createDateObj = [];
      this.subTimeObj = [];
      this.approvedTimeObj = [];
      this.financialApprovedTimeObj = [];
      this.handleQuery();
    },
    // 多选框选中数据
    handleSelectionChange(selection) {
      this.ids = selection.map((item) => item.orderId);
      this.single = selection.length !== 1;
      this.multiple = !selection.length;
      this.selRows = selection;
      // console.log(this.ids,selection,'handleSelectionChange')
    },
    getBrandList() {
      listBrand({
        pageNum: 1,
        pageSize: 500,
      }).then(({ rows }) => {
        this.brandList = rows;
      });
    },

    /** 导出按钮操作 statistic/export */
    handleExport() {
      if (!this.ids.length) {
        this.$message.error("请勾选要导出的订单");
        return;
      }
      var idsArr = [];
      for (var i = 0; i < this.ids.length; i++) {
        var item = this.ids[i];
        var obj = {
          orderId: item,
        };
        idsArr.push(obj);
      }
      this.downloadExcel(
        "qb/app/order/export",
        idsArr,
        `墙布订单_${new Date().getTime()}.xlsx`
      );
      this.$refs.tableList.clearSelection();
    },
    // 返单
    async handleReturn(row) {
      this.returnOrderOpen = true;
      const data = await this.getOrderData(row.orderId);
      this.$nextTick(() => {
        this.$refs.returnOrder.form = { ...data };
        this.$refs.returnOrder.list = data.productList;
        this.$refs.returnOrder.form.clientName = row.clientName;
      });
    },
    getSummaries(param) {
      const { columns, data } = param;
      var arr = [
        "totalPrice",
        "pocketMoney",
        "attr2",
        "attr4",
        "attr1",
        "packingFee",
        "logisticsFee",
        "zeroCutFee",
      ];
      const sums = [];
      columns.forEach((column, index) => {
        var bor = false;
        if (
          arr.length > 0 &&
          arr.find((item) => item == column.property) != undefined
        ) {
          bor = true;
        }
        if (index === 1) {
          sums[index] = "合计";
        } else {
          const values = data.map((item) => Number(item[column.property]));
          if (!values.every((value) => isNaN(value)) && bor) {
            sums[index] = Number(
              values
                .reduce((prev, curr) => {
                  const value = Number(curr);
                  if (!isNaN(value)) {
                    return prev + curr;
                  } else {
                    return prev;
                  }
                }, 0)
                .toFixed(2)
            );
          }
        }
      });
      return sums;
    },
  },
};
</script>
<style lang="scss" scoped>
::v-deep .el-dialog__body {
  padding: 6px 20px !important;
}
.dialog-footer {
  display: flex;
  justify-content: flex-end;
}
</style>
